//
//  RegionPicker.m
//  NoNeedle
//
//  Created by Ming Tian on 2017/3/13.
//  Copyright © 2017年 Ming Tian. All rights reserved.
//

#import "RegionPicker.h"

@implementation RegionPicker

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if(self) {
        [self createUI];
    }
    return self;
}

- (void)cancelButtonTapped {
    [self setHidden:YES];
}

- (void)createUI {
    self.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.45];
    self.bgView = [[UIView alloc]init];
    self.pickerView = [[UIPickerView alloc]init];
    self.cancelButton = [[UIButton alloc]init];
    self.confirmButton = [[UIButton alloc]init];
    
    self.bgView.backgroundColor = [UIColor whiteColor];
     
    [self.cancelButton setTitle:@"取消" forState:UIControlStateNormal];
    [self.confirmButton setTitle:@"确定" forState:UIControlStateNormal];
    
    [self.cancelButton setTitleColor:NavBackColor forState:UIControlStateNormal];
    [self.confirmButton setTitleColor:NavBackColor forState:UIControlStateNormal];
    
    self.cancelButton.titleLabel.font = [UIFont systemFontOfSize:15];
    self.confirmButton.titleLabel.font = [UIFont systemFontOfSize:15];
    
    [self.cancelButton addTarget:self action:@selector(cancelButtonTapped) forControlEvents:UIControlEventTouchUpInside];
    
    [self addSubview:self.bgView];
    [self addSubview:self.pickerView];
    [self addSubview:self.cancelButton];
    [self addSubview:self.confirmButton];
    
    [self layoutSubviews];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self);
        make.width.equalTo(self);
        make.height.mas_equalTo(235);
    }];
    
    [self.pickerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self);
        make.width.equalTo(self);
        make.height.mas_equalTo(200);
    }];
    
    [self.cancelButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.pickerView.mas_top).offset(-5);
        make.left.equalTo(self).offset(20);
        make.width.mas_equalTo(40);
        make.height.mas_equalTo(20);
    }];
    
    [self.confirmButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.pickerView.mas_top).offset(-5);
        make.right.equalTo(self).offset(-20);
        make.width.mas_equalTo(40);
        make.height.mas_equalTo(20);
    }];
}

@end
